home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: Problem with c code, please help!
- Date: 19 Jan 1996 07:51 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <19JAN199607513990@erich.triumf.ca>
- References: <surgsw-1901960148530001@128.206.206.86>
- NNTP-Posting-Host: erich.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <surgsw-1901960148530001@128.206.206.86>, surgsw@mizzou1.missouri.edu (Joel Weinstein) writes...
- >I have been trying to get this very simple piece of code to work for
- >hours. What is the problem???????
- >
- >#include <stdio.h>
- >
- >main()
- >{
- > int i=0;
- > char word[100], c;
- > printf("Enter a word: ");
- > while( (c = getchar()) != '\n') {
- > *word = c;
- > word == word + 1;
-
- word is the name of an array, and cannot be incremented or otherwise changed -
- if it could, you would lose access to the array. The name of an array can often
- be treated as a const pointer to the first element of an array.
-
- word == word+1; _compares_ word to word+1 - it doesn't do an assignment.
-
- To do what you want, you need a _real_ char pointer variable like:
-
- int i = 0;
- char word[100], c;
- char* temp;
-
- temp = word; /* set temp to point to the start of the array */
- while((c = getchar()) != '\n') {
- *temp++ = c;
- }
- *temp = '\0';
- temp = word; /* reset temp to the start of the array */
- /* and use temp instead of word below... */
-
- >
- > printf("You entered: ");
- > while( *word != '\n' )
- > {
- > putchar( *word );
- > word == word + 1;
- > }
- >}
- >
- >ps: is there a way to find out what exactly error messages mean? I kept
- >getting something similar to: not an Ivalue. It would be nice if I knew
- >what the hell that meant.
-
- The message was probably "not an Lvalue" - which means "word" is not something
- that can be put on the left side of an equal sign.
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
-
-
-
-
-
-
-
-
-
-
-
-